package com.example.myapplication;

import android.app.Application;
import android.content.Context;

import com.example.jtt1078_audio.constants.Constants;

import java.io.InputStream;
import java.util.Properties;

public class MyApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        parseConfig(base);
    }

    private void parseConfig(Context context){
        Properties properties = new Properties();
        InputStream inputStream = null;
        try {
            inputStream = context.getAssets().open("config.properties");
            properties.load(inputStream);
            Constants.ip = properties.getProperty("server.ip");
            Constants.port = Integer.parseInt(properties.getProperty("server.port"));
            Constants.deviceId = properties.getProperty("device.id");
            Constants.logicalChannel = Integer.parseInt(properties.getProperty("logical.channel"));
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if(inputStream != null){
                    inputStream.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
}
